﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace InSafetyAirClient.GUI.Airline
{
    public partial class UpdateA : UserControl
    {
        List<InSafetyAirClient.InSafetyAirService.AirLine> aipl = null;

        public UpdateA()
        {
            InitializeComponent();
        }

        private void UpdateA_Load(object sender, EventArgs e)
        {
            if (!this.DesignMode)
            {
 
            }
        }

        private void populateList()
        {
            AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
            ServiceSingle servS = ServiceSingle.Instance;
            //
            //Search reg
            //
            aipl = servS.getService().GetAll(typeof(InSafetyAirClient.InSafetyAirService.AirLine).Name).OfType<InSafetyAirClient.InSafetyAirService.AirLine>().ToList();
            foreach (InSafetyAirService.AirLine air in aipl)
            {
                comboBox1.Items.Add(air.name);
                autoComplete.Add(air.name);
            }
            comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            comboBox1.AutoCompleteCustomSource = autoComplete;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (InSafetyAirService.AirLine airl in aipl)
            {
                if (airl.name.Equals(comboBox1.Text))
                {
                    airl.name = textBox1.Text;
                    ServiceSingle.Instance.getService().UpdateToDatabase(airl);
                }
            }
        }
    }
}
